﻿/*
创建人：longb
日期：2022-05-31
描述：查看进度看板js
*/
var page = {
    workflowstepid: getParam("id"),
    containerno: getParam("ContainerNo"),
    ContainerID: getParam("ContainerID"), //任务单ID //add by longb 2023-01-16
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSIssueCollectMaterialHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
        page.GetProgressData();
    },
    //页面事件绑定
    bind: function () {
        //去封信息
        $('#BigTabel').datagrid({
            columns: [[
		            { field: 'PRODUCTNAME', title: '大件号', width: 100, align: 'center' },
		            { field: 'PRODUCTDESC', title: '件号名称', width: 100 },
                    { field: 'FIRSTASSEMBLEQTY', title: '单台数量', width: 100 },
                    { field: 'PRODUCTBATCHNO', title: '批次号', width: 100 },
                    { field: 'TOTALCOLLECTQTY', title: '已报数量', width: 100 },
                    { field: 'OPDESC4', title: '未报数量', width: 100,formatter: function (value, row, index) { var v= row.FIRSTASSEMBLEQTY - row.TOTALCOLLECTQTY;if(v<0){return 0;}else{return v;} } },
                    { field: 'OPDESC5', title: '完成进度', width: 100,formatter: function (value, row, index) { var v=row.TOTALCOLLECTQTY/row.FIRSTASSEMBLEQTY*100;if(v>100){return "100%";}else{ return parseInt(v)+'%';} } }
                ]],
        });
       //集件信息
        $('#SmallTabel').datagrid({
            columns: [[
		            { field: 'PRODUCTNAME', title: '小件号', width: 100, align: 'center' },
		            { field: 'PRODUCTDESC', title: '件号名称', width: 100 },
                    { field: 'FIRSTASSEMBLEQTY', title: '单台数量', width: 100 },
                    { field: 'PRODUCTBATCHNO', title: '批次号', width: 100 },
                    { field: 'TOTALCOLLECTQTY', title: '已报数量', width: 100 },
                    { field: 'OPDESC4', title: '未报数量', width: 100,formatter: function (value, row, index) { var v= row.FIRSTASSEMBLEQTY - row.TOTALCOLLECTQTY;if(v<0){return 0;}else{return v;} } },
                    { field: 'OPDESC5', title: '完成进度', width: 100,formatter: function (value, row, index) { var v=row.TOTALCOLLECTQTY/row.FIRSTASSEMBLEQTY*100;if(v>100){return "100%";}else{ return parseInt(v)+'%';} }}
                ]],
        });
         $('#ToolTable').datagrid({
            columns: [[
                    { field: 'TOOLNAME', title: '工装工具编号', width: 100 },
                    { field: 'DESCRIPTION', title: '工装工具名称', width: 100 },
		            { field: 'DRAWINGNO', title: '工装工具图号', width: 100, align: 'center' },
                    { field: 'SPECIFICATION', title: '型号规格', width: 100 },
                    { field: 'TOOLTYPE', title: '工装工具类型', width: 100 },
                    { field: 'QTY', title: '需求数量', width: 100 },
                    { field: 'PREPAREQTY', title: '已准备数量', width: 100 },
                    { field: 'NOPREPAREQTY', title: '未准备数量', width: 100,formatter: function (value, row, index) {if(value<0){return 0;}else{return value;}} },
                    { field: 'OPDESC5', title: '完成进度', width: 100,formatter: function (value, row, index) { var v=row.PREPAREQTY/row.QTY*100;if(v>100){return '100%';}else{ return  parseInt(v)+'%';} } }
                ]],
        });
         $('#MaterialTable').datagrid({
            columns: [[
		            { field: 'AUXMATERIALNAME', title: '物料编码', width: 100, align: 'center' },
		            { field: 'DESCRIPTION', title: '物料描述', width: 100 },
                    { field: 'SPECIFICATION', title: '型号规格', width: 100 },
                    { field: 'RESOURCETYPENAME', title: '材料类型', width: 100 },
                    { field: 'QTY', title: '需求数量', width: 100 },
                    { field: 'PREPAREQTY', title: '已准备数量', width: 100 },
                    { field: 'NOPREPAREQTY', title: '未准备数量', width: 100,formatter: function (value, row, index) {if(value<0){return 0;}else{return value;}}  },
                    { field: 'OPDESC5', title: '完成进度', width: 100, width: 100,formatter: function (value, row, index) {if(row.PREPAREQTY==undefined||row.QTY==0){return "0%";}else{ return  parseInt(row.PREPAREQTY/row.QTY*100)+'%'; }}  }
                ]],
        });
          $('#EquTable').datagrid({
            columns: [[
		            { field: 'SPECNO', title: '设备编码', width: 100, align: 'center' },
		            { field: 'OPDESC', title: '设备名称', width: 100 },
                    { field: 'OPDESC1', title: '型号规格', width: 100 },
                    { field: 'OPDESC2', title: '设备类型', width: 100 },
                    { field: 'OPDESC3', title: '状态', width: 100 },
                    { field: 'OPDESC4', title: '设备编号', width: 100 },
                    { field: 'OPDESC6', title: '设备状态', width: 100 }
                ]],
        });
        
    },
    //查询任务单信息
    GetProgressData: function () {
        var param = {
            action: "GetProgressData",
            id: page.workflowstepid,
            containerno:page.containerno,
            ContainerID: page.ContainerID, //add by longb 2023-01-16
            type:''
        };
        page.post(param, function (res) {
            $('#OrderForm').form('load',res.ReturnData)
            $('#BigTabel').datagrid('loadData', res.DBDataSet.bigTable);
            $('#SmallTabel').datagrid('loadData', res.DBDataSet.smallTable);
            $('#ToolTable').datagrid('loadData', res.DBDataSet.toolsTable);
            $('#MaterialTable').datagrid('loadData', res.DBDataSet.auxMaterialTable);
            if (res.Result) {
              
            }
        });
    },
   
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});